get-the-solution

ILT0005: runtime.win10-arm.microsoft.net.native.compiler tools ARM nutc_driver.exe intermediate MDIL...rsp' returned exit code -1073741819

By
on Regards: .NET Framework; C#; UWP;

Possible workaround when .Net Native fails

When creating app Packages for windows store, the ARM version faild with:

   3> Processing application code
   3> Computing application closure and generating interop code
   3> Loading 130 modules...
   3> Generating code...
   3> Interop code generated.
   3> Compiling interop code
   3> Generating System.Reflection.DispatchProxy proxy code.
   3> Cleaning up unreferenced code
   3> Generating native code
   3>C:\Program Files (x86)\Microsoft SDKs\UWPNuGetPackages\microsoft.net.native.compiler\2.2.7-rel-27913-00\tools\Microsoft.NetNative.targets(801,5): error : ILT0005: 'C:\Program Files (x86)\Microsoft SDKs\UWPNuGetPackages\runtime.win10-arm.microsoft.net.native.compiler\2.2.7-rel-27913-00\tools\ARM\ilc\Tools64\nutc_driver.exe @"C:\ResizeImage.UWP\Image.Manipulation.Shell\obj\ARM\Release\ilc\intermediate\MDIL\Get.the.solution.Image.Manipulation.Shell.rsp"' returned exit code -1073741819
   ========== Build: 2 succeeded, 1 failed, 5 up-to-date, 0 skipped ==========
   ========== Package: 0 succeeded, 1 failed ===========
   ========== App Bundle: 0 succeeded, 1 failed ===========

Matt from .Net Native was so kind to help me out here with the following:

It’s quite likely that the optimizer has botched something. One interesting check is:

  • Set to DEBUG config
  • Turn on .NET Native in the DEBUG config (Project Properties > BUILD > Enable .NET Native)
  • Build and see if it repros!

This config will disable the optimizer for your entire project. If it causes the issue to disappear then it’s just a hunt to see which methods/types we’re having trouble with. If it works in the DEBUG configuration but with .NET Native enabled then you may be able to get a working RELEASE build by selectively disabling the optimizer. Here’s an example of how to do this by Type/Namespace/Assembly:

  • Open Properties.rd.xml
  • Add: <Type Name=”FullyQualified.TypeName” DoNotOptimize=”true” DoNotInline=”true”/>
  • Or: <Namespace Name=”Name.Space” DoNotOptimize=”true” DoNotInline=”true”/>
  • Or: <Assembly Name=”Assembly.Name.Without.Extension” DoNotOptimize=”true” DoNotInline=”true”/>

Disabling things one assembly at a time lets you make reasonable progress without driving yourself mad. If that strategy ends up working out for you, then you’re good to go. The Default.rd.xml file comes along when you submit your application to the Store so the Store compile will look more or less identical to your local compile.

I followed the above steps and was able to figure out that the ImageSharp assembly or one of its dependcies caused the issue. So I added an entry for ImageSharp in Properties\Default.rd.xml to disable .NET Native and volia, the ARM Release build could be completed!

    <Assembly Name="SixLabors.ImageSharp" DoNotOptimize="true" DoNotInline="true" />

The downside of this workaround is that .NET Native for ImageSharp is disabled for the other platforms (x86 and x64) as well (when publishing) which has a big perfomance impact. For example resizing a gif picture using ImageSharp with .NET Native enabled takes about 40s while the disabled version execution time is around one minute and 20 seconds!

A manual workaround would be to create a seperate appxupload package for each platform and adjust the Default.rd.xml to enable (DoNotOptimize="false") and disable (DoNotOptimize="true") .NET Native for ImageSharp before building it. The result would be to have one ARM and one x64|x86 appxupload package which is not ideal.

A much more elegant way would be to automate the enabling and disabling process of .NET Native for ImageSharp. As the Default.rd.xml is a simple xml file we can create a simple powershell script which disables the .NET Native for ImageSharp on the ARM platform and enables it for all other platforms for us. I named the script dotnativeAdapter.ps1 which expects the used platform (x86,x64,ARM or ARM64) as parameter. Based on this parameter we decide how to set DoNotOptimize in Default.rd.xml.

   param([string]$platform)

   Write-Host $platform

   $file = "./Properties/Default.rd.xml"
   $xml = [xml](Get-Content($file))

   if($platform.ToLower() -contains 'arm') 
   {
     Write-Host "disable native for SixLabors.ImageSharp for $platform"
     $xml.Directives.Application.Assembly[1].DoNotOptimize="true";
     $xml.Directives.Application.Assembly[1].DoNotInline="true";
   }
   else
   {
     Write-Host "enable native for SixLabors.ImageSharp for $platform"
     $xml.Directives.Application.Assembly[1].DoNotOptimize="false";
     $xml.Directives.Application.Assembly[1].DoNotInline="false";
   }

   $xml.Save($file)

Now we must intercept before the build process gets triggered to execute our powershell script. This can be accomplised by unloading the the .csproj and add the following lines at the end of the document:

  ...
  <Target Name="BeforeBuild">
    <Message Text="Adapting Default.rd.xml for $(Platform)" Importance="normal" />
    <Exec Command="powershell.exe -NonInteractive -executionpolicy Unrestricted -command &quot;&amp; { .\dotnativeAdapter.ps1 $(Platform) } &quot;" LogStandardErrorAsError="True" ContinueOnError="False" WorkingDirectory="$(MSBuildProjectDirectory)" />
  </Target>
  ...
</Project>

With this approach things get much easier - we don’t need to worry about creating multiple appxupload files or forgetting to adjust the Default.rd.xml and also it’s a good solution when working with azure-pipelines.